<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
	  <div class="layui-form-item">
		<label class="layui-form-label">ID</label>
		<div class="layui-input-inline">
		  <input id="uid"  type="text" name="uid" required  lay-verify="required|number"  autocomplete="off" class="layui-input" readonly="readonly">
		</div>		
	  </div>
	  <div class="layui-form-item">
		<label class="layui-form-label">姓名</label>
		<div class="layui-input-inline">
		  <input id="username" type="text" name="username" required  lay-verify="required"  autocomplete="off" class="layui-input">
		</div> 	  
	  </div>
	 <div class="layui-form-item">
		<label class="layui-form-label">个人电话</label>
		<div class="layui-input-inline">
		  <input id="phone" type="text" name="phone" required  lay-verify="required|phone"  autocomplete="off" class="layui-input">
		</div>
	  </div>	  
	  <div class="layui-form-item">
		<label class="layui-form-label">住址</label>
		<div class="layui-input-inline">
		  <input id="address" type="text" name="address" required  lay-verify="required"  autocomplete="off" class="layui-input">
		</div>
	  </div>
      <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">更新信息</button>
        </div>
      </div>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/my.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert("是否提交", 
			 function () {
                // 关闭弹出层
                layer.close(index);
                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);
				$.ajax({
					url: globalAddress+'/selluser/update',
					type: 'post',
					data: JSON.stringify(data.field),
					dataType: "json",
					contentType: "application/json",
					success:function(response){
						if(response.code==200){
							alert("修改成功！");
							window.parent.location.reload();
						}else{
							layer.alert("修改失败！");
						}									
					},
					error:function(){
						layer.alert("交互出现错误！请联系管理员！");
					}	
				});
            });
            return false;
        });				
		var uid = $('#uid',parent.document).text();
		$("#uid").val(uid);
		 
		
		 
		 setOldMess(uid);	 	 
		// 获取并初始化修改表单 
		function setOldMess(uid){
			$.ajax({
				url: globalAddress+"/selluser/getById/"+uid,
				type:"get",
				success:function(data){
					console.log(data);
					$("#username").attr("value",data.data.username);
					$("#address").attr("value",data.data.address);
					$("#phone").attr("value",data.data.phone);																																																						
				}
			});	
		}
    });
</script>
</body>
</html>